define(["PDUtilDir/grid","PDUtilDir/searchBlock","PDUtilDir/slidebar","PDUtilDir/fileupload/multiFileUpload","PDUtilDir/inputSelect","PDUtilDir/tool", 
        "PDUtilDir/util",'PDAppDir/properties',"PicView","css!picViewCss", "Date","DateCN", "css!DateCss"],
		function(Grid,SearchBlock,Slidebar,MFU,inputSelect,Tool,Util,Properties){


	var uploadPotos = new Array();
    function init(){
        SearchBlock.init('searchBlockId');
        var provinces = null;
//        getProvince();
        queryProjectData();
        queryTeamData();
        initGrid(null);
        initQueryTime();
        //初始化
     
       
    }
    var initQueryTime = function(){
    	 $("#startTime").datetimepicker({
             //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
             language : "cn",
             //输出格式化
             format : 'yyyy-mm-dd hh:ii:ss',
             //直接选择‘今天’
             todayBtn : true,
             //设置最精确的时间选择视图
             minView : 'hour',
             //高亮当天日期
             todayHighlight : true,
             //显示“上午”“下午”
             showMeridian : true,
             //选择完毕后自动关闭
             autoclose : true
         });
     	 $("#endTime").datetimepicker({
             //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
             language : "cn",
             //输出格式化
             format : 'yyyy-mm-dd hh:ii:ss',
             //直接选择‘今天’
             todayBtn : true,
             //设置最精确的时间选择视图
             minView : 'hour',
             //高亮当天日期
             todayHighlight : true,
             //显示“上午”“下午”
             showMeridian : true,
             //选择完毕后自动关闭
             autoclose : true
         });
    }
    var initGrid =function(param){
    	 Grid({
             id:"DemoGirdDivId",
             pageSize:10,
             index:true,
             multi:true,
             pagination : true,
             cache:false,
             layout:[
                 {name:"员工姓名",field:"name",sort:true,
               /* 	 click:function(e){
                 	var data = e.data.row;
                     saveOrUpdate(data);
                 }*/
                 },
                 {name:"员工编号",field:"personNo",sort:true},
                 {name:"项目",field:"projectName",sort:true},
                 {name:"队伍",field:"teamName",sort:true},
                 {name:"工种",field:"workerName",width:"10%"},
                 {name:"签到类别",field:"inorout",format:function(obj){
                	 if(obj.row.inorout=='1'){
                		 return "进";
                	 }else{
                		 return "出";
                	 }
                 }},
                 {name:"打卡时间",field:"snapTime"}
             ],
             toolbar:[
          /*       {name:"添加",icon:"fa fa-plus-circle",callback:function(event){
              
                     saveOrUpdate(null);
                 }},
                 {name:"删除",icon:"fa fa-trash-o",callback:function(event){
                 	deleteBySelectIds();
                 }},*/
                 {name:"查询",icon:"fa fa-search",callback:function(event){
                	 initGrid(getQueryParam());
                 }}
             ],
         	data : {
 				type : "URL",
 				value : getServer() + "/flea/hclv/face/selectAll.htmls",
 			},
 			 queryParam:param
         });
    	 
    }
    

    var queryProjectData = function(){
    	$.ajax({
    		url:getServer()+"/flea/hclv/getDictHTProject.htmls",
    	
    		success:function(data){
    			var levels = data.data;
    			queryProjectSelect(levels,null);
    		}
    	});
    }
    var queryTeamData = function(){
    	$.ajax({
    		url:getServer()+"/flea/hclv/getTeams.htmls",
    		
    		success:function(data){
    			var levels = data.data;
    			queryTeamSelect(levels,null);
    		}
    	});
    }
    var queryProjectSelect = function(leves,initLevel){
    	inputSelect.dropCache();
    	inputSelect({
    		id:"projectName",
    		key : {
    			id : "dictCode",
    			name : "dictName",
    			data : "data",
    		},
    		data :leves,
    		searchAble : true,
    		initData:[initLevel],
    		callback : function(id, data) {
    			var str = "";
    			$.each(data, function(i, n){
    				str += n.dictCode;
    			})
    			$("#projectCode").val(str);
    		}
    	});
    }
    var queryTeamSelect = function(leves,initLevel){
    	inputSelect.dropCache();
    	inputSelect({
    		id:"teamName",
    		key : {
    			id : "dictCode",
    			name : "dictName",
    			data : "data",
    		},
    		data :leves,
    		searchAble : true,
    		initData:[initLevel],
    		callback : function(id, data) {
    			var str = "";
    			$.each(data, function(i, n){
    				str += n.dictCode;
    			})
    			$("#teamCode").val(str);
    		}
    	});
    }

    var getQueryParam = function(){
    	var param = {
    			personName:$("#personName").val(),
    			projectCode:$("#projectCode").val(),
    			teamCode:$("#teamCode").val(),
    			startTime:$("#startTime").val(),
    			endTime:$("#endTime").val(),
    			/*queryLevel:$("#queryLevel").val(),
    			queryProvince:$("#queryProvince").val(),
    			queryCity:$("#queryCity").val(),
    			queryZone:$("#queryZone").val(),*/
    	}
    	return param;
    }
    

    var initPicViewr = function(settings){
    	var id = settings.placeAt;
    	var fileList = settings.fileLists;
    	for(var i=0;i<fileList.length;i++){
    		var file = fileList[i];
    		$('#'+id).append('<li><img data-original='+Properties.URL_FILE_SERVER_URL+file.path+' src="'+Properties.URL_FILE_SERVER_URL+file.path+'" alt="sss"></li>');
    	}
    }
    

    
    
    

    return {
        init:init
    }
});